package com.foxzzz.two.pointers;

public class Solution125 {
    public boolean isPalindrome(String s) {
        if (s.length() < 2) {
            return true;
        }
        int start = -1;
        int end = s.length();
        while (start < end) {
            char st = 0;
            while ((st > '9' && st < 'A') || st > 'Z' || st < '0') {
                start++;
                if (start > end || start > s.length() - 1) {
                    return true;
                }

                st = s.charAt(start);
                if (st >= 'a' && st <= 'z')
                    st = (char) (st & 0xDF);
            }
            char ed = 0;
            while ((ed > '9' && ed < 'A') || ed > 'Z' || ed < '0') {
                end--;
                if (start > end || end < 0) {
                    return true;
                }
                ed = s.charAt(end);
                if (ed >= 'a' && ed <= 'z')
                    ed = (char) (ed & 0xDF);
            }
            if (st != ed) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(new Solution125().isPalindrome("0P"));
        System.out.println(new Solution125().isPalindrome(".,"));
        System.out.println(new Solution125().isPalindrome("ab"));
        System.out.println(new Solution125().isPalindrome("A man, a plan, a canal: Panama"));
        System.out.println(new Solution125().isPalindrome("race a car"));
        System.out.println(new Solution125().isPalindrome("a."));
    }
}
